package cn.xo68.boot.web.web.exception;


import cn.xo68.boot.web.properties.WebCoreProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

@ConditionalOnMissingBean( name = {"errorPageRegistrar"})
@Component
public class ErrorPageHandle implements ErrorPageRegistrar {

    private final WebCoreProperties webCoreProperties;

    public ErrorPageHandle(WebCoreProperties webCoreProperties){
        this.webCoreProperties=webCoreProperties;
    }

    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        ErrorPage errorPage=new ErrorPage(HttpStatus.NOT_FOUND, webCoreProperties.getSystemErrorRedirtPath());
        registry.addErrorPages(errorPage);
    }
}
